/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2024-04-05
 * Time: 17:45
 */
public class MyQueue {
    public static class ListNode{
        public int val;
        public  ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    ListNode head;
    ListNode end;
    public void offer(int val){
        ListNode Node = new ListNode(val);
        if(head == null){
            head = end = Node;
        }
        end.next = Node;
        Node.prev = end;
        end = Node;
    }
    public int poll(){
        if(head == null){
            return -1;
        }
        int ret = head.val;
        if(head.next == null){
            head = null;
            end = null;
        }else {
            head = head.next;
            head.prev = null;
        }
        return ret;
    }
    public int peek(){
        if(head == null){
            return -1;
        }
        return head.val;
    }
    public int size(){
        if(head == null){
            return 0;
        }
        ListNode cur = head;
        int count = 0;
        while(cur != null){
            cur = cur.next;
            count++;
        }
        return count;
    }
    public  boolean Empty(){
        return head == null;
    }
}
